//
//  BKSearch_CustomTextField.m
//  bestkeep
//
//  Created by yons on 16/11/21.
//  Copyright © 2016年 utouu. All rights reserved.
//

#import "BKSearch_CustomTextField.h"


@implementation BKSearch_CustomTextField

/**
 *  设置Placeholder
 */
- (void)customWithPlaceholder: (NSString *)placeholder color: (UIColor *)color font: (UIFont *)font {
    
    self.placeholder = placeholder;
    [self setValue:color forKeyPath:@"_placeholderLabel.color"];
    [self setValue:font forKeyPath:@"_placeholderLabel.font"];
}


/**
 *  重写这个方法是为了使Placeholder居中，如果不写会出现类似于下图中的效果，文字稍微偏上了一些
 */
- (void)drawPlaceholderInRect:(CGRect)rect {
    
    [super drawPlaceholderInRect:CGRectMake(0, self.frame.size.height * 0.5-3, 0, 0)];
}

/**
 *  控制编辑文本的位置
 */
-(CGRect)editingRectForBounds:(CGRect)bounds

{
    
    
    CGRect inset = CGRectMake(bounds.origin.x +10, bounds.origin.y, bounds.size.width -10, bounds.size.height);
    
    return inset;
    
}

/**
 *  控制显示文本的位置
 */
-(CGRect)textRectForBounds:(CGRect)bounds

{
    
    CGRect inset = CGRectMake(bounds.origin.x +10, bounds.origin.y, bounds.size.width -10, bounds.size.height);
    
    return inset;
    
    
}

- (CGRect)placeholderRectForBounds:(CGRect)bounds{
    CGRect inset = CGRectMake(bounds.origin.x +10, bounds.origin.y+3, bounds.size.width -10, bounds.size.height);
    
    return inset;
}


@end
